<?php

/*
Process Edit Game (admin_edit_game.pro.php)
*/

$rank_check = "7";
include "../global.inc.php";

$game=$_GET['game'];
$edit_game_name=$_POST['edit_game_name'];
$edit_point_name=$_POST['edit_point_name'];
$use_logo=$_POST['use_logo'];

$directoryName = "../images/user_images/opg_$game";
if (!file_exists($directoryName)) { mkdir($directoryName, 0777); }

if ($HTTP_POST_FILES['gameLogo']['size'] >= 32000)
{
	die(header(error("admin_edit_game.php?game=$game", "Your image must be under 32,000 bytes (or 32kb)")));
}

if (!eregi("image/", $HTTP_POST_FILES['gameLogo']['type']))
{
	die(header(error("admin_edit_game.php?game=$game", "You can only use .gif, .jpg, and .jpeg files for images. Please convert the image to one of these file types.")));
}

if ((!$edit_game_name) OR (!$edit_point_name))
{
	die(header(error("admin_edit_game.php?game=$game", "Please do not leave any required information blank!")));
}

mysql_query("UPDATE game_tables SET game_name = '$edit_game_name' WHERE id = '$game'") or die(mysql_error());
mysql_query("UPDATE game_tables SET point_var = '$edit_point_name' WHERE id = '$game'") or die(mysql_error());
mysql_query("UPDATE game_tables SET use_logo = '$use_logo' WHERE id = '$game'") or die(mysql_error());
	
$file = $HTTP_POST_FILES['gameLogo']['tmp_name'];
$dest = "../images/user_images/opg_$game/logo.gif";

if (file_exists($dest)) { unlink($dest); }
copy($file, $dest);

header("Location: admin_edit_game.php?game=$game&error=Your+game+has+been+edited.");

?>
